var appendCss = function(css){
    var el = document.createElement('style');
    el.innerHTML = css;
    document.head.appendChild(el);
};

var getQueryString = function(name){
    var queryJson = {};
    var search = window.location.search;
    search = search.replace(/^\?/,'');
    var fields = search.split('&');
    fields && fields.forEach(function(field){
        var arr = field.split('=');
        queryJson[arr[0]] = arr[1];
    });

    return queryJson[name];
};

window.onMessage = function(name,callback){
    var msgs = window.onMessage[name] = window.onMessage[name] || [];
    if(msgs.indexOf(callback)===-1){
        msgs.push(callback);
    }
};

window.sendMessage = function(name,param){
    var msgs = window.onMessage[name] || [];
    msgs.forEach(function(msg){
        msg(param);
    })
};

window.removeMessage = function(name,callback){
    if(callback && window.onMessage[name]){
        window.onMessage[name].forEach(function(fun,index){
            if(fun===callback){
                window.onMessage[name].splice(index,1);
            }
        })
    }else{
        delete window.onMessage[name];
    }
};